package com.lexandro.lemuplayerbot.configuration;

import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.lexandro.lemuplayerbot.service.LemuPlayerBotService;
import com.lexandro.lemuplayerbot.service.PlayerUILemubotService;
import com.lexandro.lemuplayerbot.ui.PlayerUI;
import com.lexandro.lemuplayerbot.webdriver.WebDriverPlayerUI;

@Configuration
public class AppConfig {

	private static final String LEMUPLAYERBOT_PROPERTIES = "lemuplayerbot.properties";
	private static final boolean ENABLE_JAVASCRIPT = true;

	@Bean(name = "lemuPlayerBotService")
	public LemuPlayerBotService lemuPlayerBotService() {
		return new PlayerUILemubotService();
	}

	@Bean(name = "webDriver")
	public WebDriver webDriver() {
		return new HtmlUnitDriver(ENABLE_JAVASCRIPT);
	}

	@Bean(name = "playerUI")
	public PlayerUI playerUI() {
		return new WebDriverPlayerUI();
	}

	@Bean
	public PropertyPlaceholderConfigurer propertyConfigurer() throws IOException {
		PropertyPlaceholderConfigurer properties = new PropertyPlaceholderConfigurer();
		properties.setLocations(new Resource[] { new ClassPathResource(LEMUPLAYERBOT_PROPERTIES) });
		return properties;
	}

}